/**
 *  获取url传参工具类
 *  @Authors: LiRui
 *  @date 2017-09-19
 *
 */

var QueryUtils = {
    GetQueryString: function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    },
    //保留2位小数
    fixed: function (str) {
        if (!str) str = '0.00';
        let ret = Math.round(parseFloat(str) * 100) / 100;
        let decimal = ret.toString().split('.');
        if (decimal.length === 1) {
            return ret.toString() + '.00'
        }
        ;
        if (decimal.length > 1) {
            if (decimal[1].length < 2) {
                return ret.toString() + '0'
            }
            return ret
        }
        ;
        return ret;
    },
    //千分号格式化
    fixedThousand: function (num, n) {
        //参数说明：num 要格式化的数字 n 保留小数位
        num = String(num.toFixed(n));
        var re = /(-?\d+)(\d{3})/;
        while (re.test(num)) {
            num = num.replace(re, "$1,$2");
        }
        return num;
    }
};
